﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DO = ServerDataObject;
using DataLayer;

namespace BussinesLayer
{
    public class Storage
    {
        public StorageDataContext DataContext
        {
            get
            {
                return new StorageDataContext();
            }
        }

        public List<DO.ChallengeShort> GetChallengeList(DO.ChallengeFiler filter)
        {
            using (var dc = DataContext)
            {
                return dc.Challenges.Select(q => new DO.ChallengeShort
                {
                    Id = q.ID,
                    Name = q.Name
                }).ToList();
            }
        }

        public DO.Challenge GetChallenge(Guid id)
        {
            using (var dc = DataContext)
            {
                var challenge = dc.Challenges
                    .Where(q => q.ID == id)
                    .Select(q => new DO.Challenge
                {
                    Id = q.ID,
                    Name = q.Name,
                    Description= q.Description,
                    MinScore = q.MinScore,
                    playerId = q.PlayerId,
                    Points = q.Points                    
                }).SingleOrDefault();

                //if (challenge != null)
                //{
                //    var points = dc.CheckPoints
                //        .Where(q => q.ChallengeId == id)
                //        .ToList();
                    
                //}
                return challenge;
            }
        }
    }
}
